package mvp.com.bbc.ui.presenter;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mvp.com.bbc.appContact.AppContact;
import mvp.com.bbc.bean.LoginBean;
import mvp.com.bbc.ui.model.LoginModel;

/**
 * Created by Administrator on 2017/9/29.
 */

public class LoginPresenter implements AppContact.LoginPresenter {
    private AppContact.LoginModel mLoginModel;
    private AppContact.LoginView mLoginView;

    @Inject
    public LoginPresenter(AppContact.LoginView loginView) {
        mLoginView = loginView;
        mLoginModel = new LoginModel();
    }

    @Override
    public void loginPresenter(String phone, String password) {
        mLoginModel.loginSuccess(phone, password)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<LoginBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull LoginBean loginBean) {
                        mLoginView.login(loginBean);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
